import mysql2 from 'mysql2'

const connection = mysql2.createConnection({
  host: 'localhost',
  user: 'root',
  password: '123',
  database: 'blog'
})

connection.connect()

exports.queryDatabase = (sql: string, values: never) => {
  return new Promise((resolve, reject) => {
    connection.query(sql, values, (error, results) => {
      if (error) return reject(error);
      resolve(results);
    });
  });
};
 
// Close the connection when the Node.js application stops
process.on('SIGINT', function() {
  connection.end(function () {
    process.exit();
  });
});